package com.yw.android.common.utils;

/**
 * 应用Crash处理器
 */
public class AppCrashHandler implements Thread.UncaughtExceptionHandler {
    /**
     * 默认crash处理器
     */
    private Thread.UncaughtExceptionHandler mDefaultHandler = null;

    /**
     * 构造函数
     */
    public AppCrashHandler() {
        try {
            mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
            Thread.setDefaultUncaughtExceptionHandler(this);
        } catch (Throwable t) {
            FLOG.e("init crash handler failed: " + t);
        }
    }

    @Override
    public void uncaughtException(Thread thread, Throwable t) {
        FLOG.e("thread(" + thread + ") uncaught exception", t);

        if (null != mDefaultHandler) {
            mDefaultHandler.uncaughtException(thread, t);
        }
    }
}
